import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from  DateDialog2 import DateDialog
class WindowDemo(QWidget):
    def __init__(self,parent=None):
        super(WindowDemo,self).__init__(parent)
        self.resize(400,100)
        self.setWindowTitle("多窗口信号和槽的方式")
        self.open_btn=QPushButton("获取时间")
        self.lineEdit_inner=QLineEdit(self)
        self.lineEdit_emit=QLineEdit(self)
        self.open_btn.clicked.connect(self.openDialog)
        self.lineEdit_inner.setText('接收子窗口内置信号的时间')
        self.lineEdit_emit.setText('接收子窗口自定义的信号的时间')
        grid=QGridLayout()
        grid.addWidget(self.lineEdit_inner)
        grid.addWidget(self.lineEdit_emit)
        grid.addWidget(self.open_btn)
        self.setLayout(grid)
    def openDialog(self):
        dialog=DateDialog(self)
        #连接子窗口内置信号与主窗口的槽函数

        dialog.datetime_inner.dateTimeChanged.connect(self.inner_slot)
        #连接子窗口自定义信号与主窗口的槽函数
        dialog.Signal_OneParameter.connect(self.emit_slot)
        dialog.show()

    def inner_slot(self,date):
        self.lineEdit_inner.setText(date.toString())

    def emit_slot(self,datestr):
        self.lineEdit_emit.setText(datestr)


if __name__ == '__main__':
    app=QApplication(sys.argv)
    main=WindowDemo()
    main.show()
    sys.exit(app.exec_())